//
//  MainViewController.m
//  RestaurantCar
//
//  Created by apple on 2017/5/8.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "MainViewController.h"
#import "TopMainView.h"

#import <BaiduMapAPI_Map/BMKMapView.h>
#import "MainBaiduMapView.h"
#import <SDAutoLayout.h>


@interface MainViewController () <TopMainViewDelegate,BMKMapViewDelegate>
{
    TopMainView *topView;
    MainBaiduMapView *_mainMap;
}
@end

@implementation MainViewController
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
     self.navigationController.navigationBarHidden = NO;
    // 隐藏导航底部的分割线
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init]
     
                       forBarPosition:UIBarPositionAny
     
                           barMetrics:UIBarMetricsDefault];
    
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    [_mainMap.mapView viewWillAppear];
    // 此处记得不用的时候需要置nil，否则影响内存的释放
    _mainMap.mapView.delegate = self;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    // 显示导航底部的分割线
    
    [_mainMap.mapView viewWillDisappear];
    // 不用时，置nil
    _mainMap.mapView.delegate = nil;

}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.automaticallyAdjustsScrollViewInsets = NO;
    // 取消导航的透明
    self.navigationController.navigationBar.translucent = NO;
    
    self.view.backgroundColor = [UIColor redColor];
    
    [self navigationItemSet];
    [self topButton];
    [self addBaiduMap];
    
    
    UIButton *b = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    b.frame = CGRectMake(120, 400, self.view.frame.size.width - 200, 40);
    [b setTitle:@"kkk" forState:UIControlStateNormal];
    [b setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [b addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:b];

    
}
- (void)navigationItemSet {
    // 导航Logo
    UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 2 - 50, 5, 100, 24)];
    img.image = [UIImage imageNamed:@"Page 1.png"];
    self.navigationItem.titleView = img;
    
    // 导航左按钮
    UIButton *userContext = [[UIButton alloc] initWithFrame:CGRectMake(0, 5, 20, 20)];
    [userContext  setBackgroundImage:[UIImage imageNamed:@"user.png"] forState:UIControlStateNormal];
    [userContext  addTarget:self action:@selector(leftUser) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:userContext];
    
    
}

- (void)topButton {
    topView = [[TopMainView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 30)];
    // 协议
    topView.delegate = self;
    [self.view addSubview:topView];
}
- (void)addBaiduMap {
    _mainMap = [[MainBaiduMapView alloc] initWithFrame:CGRectMake(0, topView.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
    _mainMap.frame = self.view.frame;
    [self.view addSubview:_mainMap];
    
}

#pragma mark- 用户管理界面
- (void)leftUser {
    
}
#pragma mark- 按钮事件，回调方法
- (void)selectedButtonTag:(NSInteger)index {
    
}

- (void)click {
//    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"userInto"];
//    NSLog(@"%d",[[NSUserDefaults standardUserDefaults] boolForKey:@"userInto"]);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
